﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UpdatedHomeMaker
{
    public partial class DayThing : UserControl
    {
        private DocumentedDay dayInfo;
        private Color normalColor;
        public DayThing()
        {
            dayInfo = new DocumentedDay();
            InitializeComponent();
            BackColor = Color.Red;
            refreshInfo();
        }
        public DayThing(DocumentedDay day)
        {
            InitializeComponent();
            DayInfo = new DocumentedDay(day);
            refreshInfo();
        }
        public void refreshInfo()
        {
            lblStartTimeStat.Text = dayInfo.StartTime.ToShortDateString() + " " + dayInfo.StartTime.ToShortTimeString();
            lblEndTimeStat.Text = dayInfo.EndTime.ToShortDateString() + " " + dayInfo.EndTime.ToShortTimeString();
            lblHoursMinStat.Text = dayInfo.HoursAndMin;
            lblUnitsStat.Text = dayInfo.Units.ToString();
            lblStatusStat.Text = dayInfo.Status.ToString();
        }
        public void refreshColors()
        {
            if (dayInfo.Status == PayStatus.notSubmitted)
                BackColor = Color.Red;
            else if (dayInfo.Status == PayStatus.submitted)
                BackColor = Color.Yellow;
            else
                BackColor = Color.Green;
        }
        public DocumentedDay DayInfo
        {
            get { return dayInfo; }
            set 
            { 
                dayInfo = value;
                refreshInfo();
                refreshColors();
            }
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            using (DayInformation form = new DayInformation(dayInfo))
            {
                form.ShowDialog();
                if (form.DialogResult == DialogResult.OK)
                    dayInfo = form.dayInfo;
                refreshColors();
                refreshInfo();
            }
        }
        
        private void DayThing_Enter(object sender, EventArgs e)
        {
            normalColor = BackColor;
            BackColor = ControlPaint.Dark(BackColor);
        }

        private void DayThing_Leave(object sender, EventArgs e)
        {
            BackColor = normalColor;
        }
    }
}
